package com.ruoyi.heytalk.controller.system;

import com.ruoyi.common.constant.heytalk.CommonConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.heytalk.dto.RecallChatDTO;
import com.ruoyi.common.core.domain.heytalk.dto.SendChatDTO;
import com.ruoyi.common.core.domain.heytalk.netty.ChatMsg;
import com.ruoyi.heytalk.service.ChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 聊天请求控制器
 * @author zhusy
 * @since 2021/11/10
 */
@Api(value = "聊天请求控制层", tags = {"聊天请求控制层"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping(CommonConstants.HEY_TALK)
public class ChatController extends BaseController {

    private final ChatService chatService;

    @ApiOperation("消息发送")
    @PostMapping("/chat/send")
    public AjaxResult<Object> sendChat(@Validated @RequestBody SendChatDTO sendChatDTO) {
        System.out.println("sendChatDTO====" + sendChatDTO.toString());
        return chatService.sendChat(sendChatDTO);
    }

    @ApiOperation("获取离线消息")
    @PostMapping("/chat/getMessage")
    public AjaxResult<Void> getMessage(){
        return chatService.getMessage();
    }

    @ApiOperation("消息撤回")
    @PostMapping("/chat/recall")
    public AjaxResult<Object> recallChat(@Validated @RequestBody RecallChatDTO recallChatDTO) {
        return chatService.recallChat(recallChatDTO);
    }

}
